package iamutkarshtiwari.github.io.ananas.editimage.adapter;

import iamutkarshtiwari.github.io.ananas.ResourceTable;
import ohos.agp.components.*;
import ohos.app.Context;
import ohos.global.resource.NotExistException;
import ohos.media.image.ImageSource;
import ohos.media.image.PixelMap;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class StickerAdapter extends BaseItemProvider {
    //    private StickerFragment stickerFragment;
    private List<PixelMap> pathList = new ArrayList<>();
    private Context mContext;
    List<PixelMap> type1List = new ArrayList<>();
    List<PixelMap> type2List = new ArrayList<>();
    List<PixelMap> type3List = new ArrayList<>();
    List<PixelMap> type4List = new ArrayList<>();
    List<PixelMap> type5List = new ArrayList<>();
    List<PixelMap> type6List = new ArrayList<>();
    List<List<PixelMap>> list = new ArrayList<>();

    public StickerAdapter(Context context, int i) {
        super();
        this.mContext = context;
        try {
            type1List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type1_1), new ImageSource.SourceOptions()).createPixelmap(null));
            type1List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type1_2), new ImageSource.SourceOptions()).createPixelmap(null));
            type1List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type1_3), new ImageSource.SourceOptions()).createPixelmap(null));
            type1List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type1_4), new ImageSource.SourceOptions()).createPixelmap(null));
            type1List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type1_5), new ImageSource.SourceOptions()).createPixelmap(null));
            type2List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type2_1), new ImageSource.SourceOptions()).createPixelmap(null));
            type2List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type2_2), new ImageSource.SourceOptions()).createPixelmap(null));
            type2List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type2_3), new ImageSource.SourceOptions()).createPixelmap(null));
            type2List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type2_4), new ImageSource.SourceOptions()).createPixelmap(null));
            type2List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type2_5), new ImageSource.SourceOptions()).createPixelmap(null));
            type3List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type3_1), new ImageSource.SourceOptions()).createPixelmap(null));
            type3List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type3_2), new ImageSource.SourceOptions()).createPixelmap(null));
            type3List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type3_3), new ImageSource.SourceOptions()).createPixelmap(null));
            type3List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type3_4), new ImageSource.SourceOptions()).createPixelmap(null));
            type3List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type3_5), new ImageSource.SourceOptions()).createPixelmap(null));
            type4List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type4_1), new ImageSource.SourceOptions()).createPixelmap(null));
            type4List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type4_2), new ImageSource.SourceOptions()).createPixelmap(null));
            type4List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type4_3), new ImageSource.SourceOptions()).createPixelmap(null));
            type4List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type4_4), new ImageSource.SourceOptions()).createPixelmap(null));
            type4List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type4_5), new ImageSource.SourceOptions()).createPixelmap(null));
            type5List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type5_1), new ImageSource.SourceOptions()).createPixelmap(null));
            type5List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type5_2), new ImageSource.SourceOptions()).createPixelmap(null));
            type5List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type5_3), new ImageSource.SourceOptions()).createPixelmap(null));
            type6List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type6_1), new ImageSource.SourceOptions()).createPixelmap(null));
            type6List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type6_2), new ImageSource.SourceOptions()).createPixelmap(null));
            type6List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type6_3), new ImageSource.SourceOptions()).createPixelmap(null));
            type6List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type6_4), new ImageSource.SourceOptions()).createPixelmap(null));
            type6List.add(ImageSource.create(mContext.getResourceManager().getResource(ResourceTable.Media_type6_5), new ImageSource.SourceOptions()).createPixelmap(null));
        } catch (IOException | NotExistException e) {
            e.printStackTrace();
        }
        list.add(type1List);
        list.add(type2List);
        list.add(type3List);
        list.add(type4List);
        list.add(type5List);
        list.add(type6List);
        pathList = list.get(i);
    }

    public List<PixelMap> getShowIcon() {
        return pathList;
    }

    @Override
    public int getCount() {
        return pathList.size();
    }

    @Override
    public Object getItem(int i) {
        return pathList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
        final Component cpt;
        if (component == null) {
            cpt = LayoutScatter.getInstance(mContext).parse(ResourceTable.Layout_view_sticker_item, null, false);
        } else {
            cpt = component;
        }
        Image image = (Image) cpt.findComponentById(ResourceTable.Id_img);
        image.setPixelMap(pathList.get(i));
        return cpt;

    }

}
